package test;

import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class Demo {
	static String publicKey;
	static String privateKey;
	static double EARTH_RADIUS = 6378.137;
	static HashMap<String, String> map;
	/*
	 * static { try { Map<String, Object> keyMap = RSAUtils.genKeyPair();
	 * publicKey = RSAUtils.getPublicKey(keyMap); privateKey =
	 * RSAUtils.getPrivateKey(keyMap); System.err.println("��Կ: \n\r" +
	 * publicKey); System.err.println("˽Կ�� \n\r" + privateKey); } catch
	 * (Exception e) { e.printStackTrace(); } }
	 */

	public static void main(String[] args) throws Exception {
		/*
		 * Date date = new Date(); System.out.println(date.getTime()); long mil
		 * = System.currentTimeMillis(); System.out.println(mil);
		 * SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"
		 * ); System.out.println(format.format(mil)); Date date1 = format.parse(
		 * "2016-3-04 01:23:54"); System.out.println(date1.getTime());
		 */
		/*
		 * System.out.println(format.format(date1)); Date date2 = new Date(
		 * "2014-03-12 16:04:45"); System.out.println(format.format(date2));
		 * LocalDate localDate = LocalDate.now(); System.out.println(localDate);
		 * LocalTime localTime = LocalTime.now().withNano(0);
		 * System.out.println(localTime); LocalTime localTime2 =
		 * LocalTime.parse("14:34:43");
		 * System.out.println(localTime2.toString()); LocalDate localDate2 =
		 * LocalDate.parse("2018-03-12");
		 * System.out.println(localDate2.toString());
		 */
		/*
		 * float a = 50.57f; float b = 49.43f;
		 * System.out.println((int)(Math.ceil(a)));
		 * System.out.println((int)Math.floor(b));
		 */
		/*
		 * String vtime = "2016-03-04 01:23:54";
		 * System.out.println("'"+vtime+"'");
		 */
		/*
		 * String i="12"; if(i==null||(!i.equals("0")&&!i.equals("1"))){
		 * System.out.println("helo"); }
		 */
		/*
		 * Map<String, Integer> m = new HashMap<>(); int i1 = 2; Integer i2 =
		 * new Integer(2);
		 * 
		 * m.put("hehe", i1); ArrayList< Integer> ar = new ArrayList<>();
		 * ar.add(i2); long r = 9223372036854775800l; int w = 1234; Random
		 * random = new Random(); System.out.println(random.nextInt());
		 * System.out.println(-1>>1); System.out.println(-1>>1); int a = (int)
		 * 1.0; char b = 'c'; float f = b;
		 */
		// System.out.println( f);
		/*
		 * String d = "w3d"; byte[] e = d.getBytes("utf-8"); byte[] c =
		 * charToByte(b); System.out.println(c[1]+" "+c[0]);
		 * System.out.println(e.length);
		 */
		/*
		 * byte[] pub =
		 * "http://open.weather.com.cn/data/?areaid=101010100&type=index_f&date=201604201317&appid=0c76ee600596c59d"
		 * .getBytes(); byte[] pri =
		 * "4a17fd_SmartWeatherAPI_996ac54".getBytes(); String hmac =
		 * getSignature(pub, pri); String base64String = "whuang123"; byte[]
		 * result = Base64.encodeBase64(hmac.getBytes());
		 */
		// System.out.println(result);
		/*
		 * Tinterface ti = new Tclass(); System.out.println(ti.test());
		 * //System.out.println(ti.inclass()); Hello he = new Tclass();
		 * System.out.println(he.hel()); Hello hee = new Hello();
		 * System.out.println(hee.hel()); Tclass tc = new Tclass();
		 * System.out.println(tc.hel());
		 */
		/*
		 * for(int i = 1;i<100000;i++){
		 * if(i%2==1&&i%3==0&&i%4==1&&i%5==1&&i%6==3&&i%7==0&&i%8==1&&i%9==0){
		 * System.out.println(i+" "); } }
		 */
		/*
		 * String a = "wei.feng@changhong.com";
		 * System.out.println(a.lastIndexOf("@"));
		 * System.out.println(a.lastIndexOf("."));
		 * System.out.println(a.substring(9,a.lastIndexOf(".")));
		 */
		/*
		 * Method method = Hello.class.getMethod("hel", String.class);
		 * method.invoke(new Hello(), "helllo");
		 */
		// tt(new Hello());
		/*
		 * List<Hello> list = new ArrayList<>(); while(true){ list.add(new
		 * Hello()); }
		 */
		/*
		 * System.err.println("��Կ���ܡ���˽Կ����"); String source =
		 * "fotejahtubplbagh"; System.out.println("\r����ǰ���֣�\r\n" + source);
		 * byte[] data = source.getBytes(); byte[] encodedData = null; try {
		 * String publicKey1 =
		 * "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2VeDZZa+W8wk5x3l17XpDXTULJeTTxNeutRlO1oNRZL0bIRAc4yzlYwtPuF/IO0C0Way0k+AOEkmLrCdiDWcRrTWOlEp0DAXXvHfw7BoIa/WGvvpzycbTo9LTPfzIpStDWJmmMYyjHjY1lwxdMlw8h56NqJkEVPsfvbzyhUXeAwIDAQAB";
		 * encodedData = RSAUtils.encryptByPublicKey(data, publicKey1); } catch
		 * (Exception e1) { e1.printStackTrace(); } String after64 = new
		 * String(Base64Utils.encode(encodedData).getBytes("UTF-8")); String
		 * afterD64 = new String(Base64Utils.decode(after64)); try {
		 * 
		 * System.out.println("���ܺ����֣�\r\n" + new String(encodedData));
		 * System.out.println("after encode by base64��" + new
		 * String(Base64Utils.encode(encodedData).getBytes("UTF-8")));
		 * System.out.println("after decode by base64: "+afterD64); } catch
		 * (Exception e1) { e1.printStackTrace(); } byte[] decodedData = null;
		 * try { String privateKey1 =
		 * "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBALZV4Nllr5bzCTnHeXXtekNdNQsl5NPE1661GU7Wg1FkvRshEBzjLOVjC0+4X8g7QLRZrLST4A4SSYusJ2INZxGtNY6USnQMBde8d/DsGghr9Ya++nPJxtOj0tM9/MilK0NYmaYxjKMeNjWXDF0yXDyHno2omQRU+x+9vPKFRd4DAgMBAAECgYBx7WTp0UyOf9rS3F17HuAW+UUsawf4ffTZ99QRW51/nPc/3T/JHPUvetxVenl2jfdW+PUde4wynqCPggi1jnRIHDF5mwoSIcfHlxy4mQ/LCjx5PLVE7XWtlw+GUrE1cs72XI+iXHQhr0abjvZQihAcrmd7c+uQ/nu7U9XYAQJQmQJBANtSlhCvgTnlRDk7kThOJAlk7shAfK6enkI5hxbynqF6AyQh8VSM0yMx4a4scWBJZSvBk9FfMScr+rRo/pOJ6JUCQQDU09YyBdt/KWntWZIsafV9SzWi4DC3jTELUZUCGflGts0dUVJZSSsz1iqZ7EveeQ0x8DtksFHc1tERDDWrSc43AkEApPzyoOi2KOx8ryVNcHLwDxUbwA8q/F2cpisKocuwY78an9Lc7gLmTmKW6GTMgWeVMR51aZrXqiUeextE745eJQJBAKWh54UuwdCJLoMlvnkKTZ+hNLD5wXBYVd71Mv5bsIC0K5WxgGE0bIb/GlCIcdNGalp/F/oYrt0r4bFeyzXvTqkCQQC+bUAr/GojgivBmXSK5LWjln1+Qko4KWJILwGPRK6F1qP7UnWBxQc7OUqLsG2CC7vCoa2onmdXFfUtt/TrD+AP";
		 * decodedData = RSAUtils.decryptByPrivateKey(encodedData, privateKey1);
		 * } catch (Exception e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); } String target = new String(decodedData);
		 * System.out.println("���ܺ�����: \r\n" + target);
		 */
		/*
		 * int[] a = {1,2,3}; for(int i:a){System.out.println(i);}
		 */
		/*
		 * double length =
		 * Math.sin(1.4)*Math.sin(0.8)+Math.cos(1.4)*Math.cos(.8)*Math.cos(2.4);
		 * double distance = 30*Math.acos(length)*Math.PI/180;
		 * System.out.println(distance);
		 */
		/*
		 * double length2 =
		 * Math.cos(Math.PI/2-rad(34.543))*Math.cos(Math.PI/2-rad(
		 * 45.654))+Math.sin(Math.PI/2-rad(34.543))*Math.sin(Math.PI/2-rad(
		 * 45.654))*Math.cos(rad(23.345-38.456)); double t = Math.acos(length2);
		 * System.out.println(t*EARTH_RADIUS);
		 * System.out.println(GetDistance(23.345, 34.543, 38.456, 45.654));
		 * System.out.println(LantitudeLongitudeDist(23.345, 34.543, 38.456,
		 * 45.654));
		 */
		/*
		 * int idCode = (int)(Math.random()*1000000); System.out.println(
		 * idCode); System.out.println( Math.random());
		 */
		/* System.out.println(UUID.randomUUID().toString()); */
		/*
		 * String a = "12345"; System.out.println(a.substring(1,a.length()));
		 */

		// finall();
		/*
		 * int[] arr = new int[5]; Random rd = new Random(); for(int
		 * i=0;i<5;i++){ arr[i] = (int)(Math.random()*100); } //int[]
		 * arr={13,43,12,12,53}; for(int i=0;i<arr.length;i++){ for(int
		 * j=i+1;j<arr.length;j++){ if(arr[i]>arr[j]){ int temp = arr[i]; arr[i]
		 * = arr[j]; arr[j] = temp; } } } for(int k = 0;k<arr.length;k++){
		 * System.out.println(arr[k]); }
		 */
		/*
		 * int j = 0; System.out.println("before:"+System.currentTimeMillis());
		 * for(int i = 0;i<3000;i++){ j++; }
		 * System.out.println("after"+System.currentTimeMillis());
		 */

		/*
		 * Integer a = 1000; int aa = 1000; Integer b = 2; Integer c = 3;
		 * Integer e = new Integer(1000); Integer f = new Integer(1000); Long g
		 * = 3l; System.out.println(a ==aa); System.out.println(e ==f);
		 * System.out.println(c ==(a+b)); System.out.println((Object)(a+b)
		 * instanceof Integer); System.out.println(c.equals(a+b));
		 * System.out.println(g ==(a+b)); System.out.println(g.equals(a+b));
		 */
		// for(int i=0;i<10000;i++){
		/*
		 * map = new HashMap<>(); for(int j=0;j<100000;j++){ map.put("key"+j,
		 * ""+j); }
		 */
		// }
		/*
		 * AtomicInteger ati = new AtomicInteger(); ati.set(3);
		 * System.out.println(ati.get());
		 */
		// System.out.println(new Date().getDate());
		// Calendar cl = Calendar.getInstance();
		// cl.add(cl.DAY_OF_MONTH, -27);
		// //cl.setFirstDayOfWeek(Calendar.SUNDAY);
		// System.out.println(cl.get(Calendar.DATE));
		// testStatic(new Hello());
		// System.out.println(java.net.InetAddress.getLocalHost().getHostAddress());
		/*
		 * Hello[] hellos = new Hello[]{new Hello(),new Hello()}; Hello[]
		 * hellos2 = {new Hello(),new Hello()}; Hello[] hellos3; hellos3 =
		 * hellos;
		 */
		// new Stest();
		// System.out.println(Tinterface.i);
		// Tinterface tinterface = new IgnoreId().geTinterface("fd", 40);
		// System.out.println(tinterface.test());
		// Inner inner = new InnerClass.Inner("ff");
		// Inner inner2 = new InnerClass().new Inner("ff");
		// String ss = new InnerClass().ss1;
		// System.out.println(inner.get());
		/*
		 * in in = new Tinterface.in(); System.out.println(in.i);
		 */
		// Inner inner = new InnerClass().new Inner();
		// System.out.println(inner.ss2);
		// System.out.println(new InnerClass().get());
		// Tclass tclass = new Tclass(new InnerClass());
		// in in = new Tclass.in();
		// System.out.println(in.i);
		// new ConstructT2();
		// String ss = "好吗，如果真的在那里";
		// System.out.println(ss.getBytes());
		// System.out.println(new String(ss.getBytes("utf8"),"ISO8859-1"));
		// String sss = new String(ss.getBytes("utf8"),"ISO8859-1");
		// System.out.println(new String(sss.getBytes("ISO8859-1"),"utf8"));
		// List<? super InnerClass.Inner> list = new ArrayList<>();
		// list.add(new Hello("1"));
		// System.out.println(list.get(0).toString());
		// List<? super InnerClass<String, String>> list1 = new ArrayList<>();
		// list1.add(new ClassWithGeneric());
		// System.out.println(list1.get(0).toString());
		// List<InnerClass.Inner> list = new ArrayList<InnerClass.Inner>();
		// list.add(new Hello());
		// System.out.println(list.get(0));
		// Class c3 = ArrayList.class;
		// Class c1 = new ArrayList<String>().getClass();
		// Class c2 = new ArrayList<Integer>().getClass();
		// System.out.println(c1 == c3);
		// InnerClass.Inner[] hellos = (InnerClass.Inner[])
		// Array.newInstance(Hello.class,10);
		// hellos[0] = new Hello();
		// hellos[1] = new Hello();
		// System.out.println((hellos[0]).getClass().getName());
		// String[] ss = {"ff","fs","fdsf"};
		// String[] ss0 = new String[1] ;
		// Set< String> set = new HashSet<>();
		// set.add("fdf");
		// set.add("fd");
		// List list = Arrays.asList(ss);
		//// List list = Arrays.asList("fdsf","fd","fdf");
		// System.out.println(list.size());
		//// Iterator<String> iterator = list.iterator();
		// List<String> ls = new ArrayList<String>();
		// ls.add("fd");
		// ls.add("g");
		// Collection<String> unmodifiableCollection =
		// java.util.Collections.unmodifiableCollection(ls);
		// List<String> lss = new ArrayList<>(unmodifiableCollection);
		// lss.add("fd");
		// ls.add("fd");
		// ls.toArray();
		// System.out.println(ss0.length);
		// iterator.next();
		// iterator.remove();
		// list.add("fd");
		// System.out.println(list.get(2));
		// String ss =new String("ff");
		// String[] st = {ss};
		// String ss1 = ss;
		// ss = ss+"ff";
		// System.out.println(ss1);
		// System.out.println(st[0]);
		// ListTest listTest = new ListTest();
		// listTest.ss = "gdg";
		// ListTest[] listTests = {listTest};
		// listTest.ss = "gdg";
		// System.out.println(listTests[0].ss);
		String[] strings = new String[] { "g", "h" };
		List<String> list = Arrays.asList(strings);
//		list.add("t");
		System.out.println(list.toArray().length);
	}

	// static Hello hello = new Hello();
	public static void testStatic(Hello hello) {
		hello.setString("ddd");
		hello.getString();
	}

	public static int finall() {
		int a = 0;
		try {
			a = 1;
			System.out.println(a);
			return a;
		} catch (Exception e) {
			// TODO: handle exception
		} finally {
			a = 2;
			System.out.println(a);
		}
		return a;
	}

	public static void tt(ListTest lt) {
		System.out.println("fff");
	}

	public static byte[] charToByte(char c) {
		byte[] b = new byte[2];
		b[0] = (byte) ((c & 0xFF00) >> 8);
		b[1] = (byte) (c & 0xFF);
		return b;
	}

	public static String getSignature(byte[] data, byte[] key) throws InvalidKeyException, NoSuchAlgorithmException {
		final String HMAC_SHA1 = "HmacSHA1";
		SecretKeySpec signingKey = new SecretKeySpec(key, HMAC_SHA1);
		Mac mac = Mac.getInstance(HMAC_SHA1);
		mac.init(signingKey);
		byte[] rawHmac = mac.doFinal(data);
		MessageDigest md = MessageDigest.getInstance("MD5");
		md.update(rawHmac);

		return md.digest().toString();
	}

	private static double rad(double d) throws Exception {
		return d * Math.PI / 180.0;
	}

	public static double GetDistance(double lon1, double lat1, double lon2, double lat2) throws Exception {
		double radLat1 = rad(lat1);
		double radLat2 = rad(lat2);
		double a = radLat1 - radLat2;
		double b = rad(lon1) - rad(lon2);
		double s = 2 * Math.asin(Math.sqrt(
				Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
		s = s * EARTH_RADIUS;
		// s = Math.round(s * 10000) / 10000;
		return s;
	}

	public static double LantitudeLongitudeDist(double lon1, double lat1, double lon2, double lat2) throws Exception {
		double radLat1 = rad(lat1);
		double radLat2 = rad(lat2);

		double radLon1 = rad(lon1);
		double radLon2 = rad(lon2);

		if (radLat1 < 0)
			radLat1 = Math.PI / 2 + Math.abs(radLat1);// south
		if (radLat1 > 0)
			radLat1 = Math.PI / 2 - Math.abs(radLat1);// north
		if (radLon1 < 0)
			radLon1 = Math.PI * 2 - Math.abs(radLon1);// west
		if (radLat2 < 0)
			radLat2 = Math.PI / 2 + Math.abs(radLat2);// south
		if (radLat2 > 0)
			radLat2 = Math.PI / 2 - Math.abs(radLat2);// north
		if (radLon2 < 0)
			radLon2 = Math.PI * 2 - Math.abs(radLon2);// west
		double x1 = EARTH_RADIUS * Math.cos(radLon1) * Math.sin(radLat1);
		double y1 = EARTH_RADIUS * Math.sin(radLon1) * Math.sin(radLat1);
		double z1 = EARTH_RADIUS * Math.cos(radLat1);

		double x2 = EARTH_RADIUS * Math.cos(radLon2) * Math.sin(radLat2);
		double y2 = EARTH_RADIUS * Math.sin(radLon2) * Math.sin(radLat2);
		double z2 = EARTH_RADIUS * Math.cos(radLat2);

		double d = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
		// 余弦定理求夹角
		double theta = Math.acos((EARTH_RADIUS * EARTH_RADIUS + EARTH_RADIUS * EARTH_RADIUS - d * d)
				/ (2 * EARTH_RADIUS * EARTH_RADIUS));
		double dist = theta * EARTH_RADIUS;
		return dist;
	}

}
